﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Messenger.Converters
{
    internal class TextTypeConverter : IValueConverter
    {
        //源数据(int)转换为目标数据(string)
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value?.ToString();//数字转字符串
            //if(value is int intvalue)
            //{
            //    return intvalue;
            //}
            //return string.Empty;
        }

        //目标数据(string)转换为源数据(int)
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return int.TryParse(value?.ToString(), out int intvalue) ? intvalue:0;//字符串转整数
            //if (value is string stringvalue && int.TryParse(stringvalue,out int result)) 
            //{
            //    return result;
            //}
            //return 0;
        }
    }
}
